(align): If the argument SIZE would overflow
authorEli Zaretskii <eliz@gnu.org>
Mon, 9 Apr 2001 10:52:43 +0000 (10:52 +0000)
committerEli Zaretskii <eliz@gnu.org>
Mon, 9 Apr 2001 10:52:43 +0000 (10:52 +0000)
__malloc_ptrdiff_t, fail right away.

src/gmalloc.c

index 751e90baf133aa65a670c1df2871ad3805882b8c..3508304da33621fea734eba8a40350027942c2da 100644 (file)
@@ -437,7 +437,14 @@ align (size)
   __ptr_t result;
   unsigned long int adj;
 
-  result = (*__morecore) (size);
+  /* align accepts an unsigned argument, but __morecore accepts a
+     signed one.  This could lead to trouble if SIZE overflows a
+     signed int type accepted by __morecore.  We just punt in that
+     case, since they are requesting a ludicrous amount anyway.  */
+  if ((__malloc_ptrdiff_t)size < 0)
+    result = 0;
+  else
+    result = (*__morecore) (size);
   adj = (unsigned long int) ((unsigned long int) ((char *) result -
                                                  (char *) NULL)) % BLOCKSIZE;
   if (adj != 0)